from telnetlib import DO

import numpy as np
from manim import *
from numpy import flip, insert
import math

LV, QL, QH, JH = '#75cfb8', '#bbdfc8', '#f0e5d8', '#ffc478'

class p1(MovingCameraScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        ax=Axes(
            x_range=[-2,2,1],
            y_range=[-1,3,1],
            x_length=6,
            y_length=6,
        )
        parabola = ax.plot(lambda x: x ** 2,x_range=[-1.5,1.5])
        o=ax.coords_to_point(0,5/4,0)
        circle=Circle(1.5).move_to(o)
        x,y=np.sqrt(3)/2,3/4
        diff=Difference(ax.plot(lambda x: x ** 2, x_range=[-x, x]),circle).set_fill(LV,1)
        self.add(parabola,circle,ax,diff)

class p2(MovingCameraScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        ax=Axes(
            x_range=[-2,2,1],
            y_range=[-1,3,1],
            x_length=6,
            y_length=6,
        )
        parabola = ax.plot(lambda x: x ** 2,x_range=[-1.5,1.5])
        o=ax.coords_to_point(0,5/4,0)
        circle=Circle(1.5).move_to(o)
        x,y=np.sqrt(3)/2,3/4
        diff=Difference(ax.plot(lambda x: x ** 2, x_range=[-x, x]),circle).set_fill(LV,1)
        self.add(parabola,circle,ax,diff)
        # p2
        a,b,c,d=ax.coords_to_point(-x,y,0),ax.coords_to_point(x,y,0),ax.coords_to_point(x,0,0),ax.coords_to_point(-x,0,0)
        oa,ob=Line(o,a),Line(o,b)
        self.add(oa,ob,
                 DashedLine(a,b),
                 DashedLine(b,c),
                 DashedLine(d,a),
                 MathTex(r'O(0,\frac{5}{4})').next_to(o,UR),
                 MathTex('A').next_to(a,LEFT),
                 MathTex('B').next_to(b),
                 MathTex('C').next_to(c,DOWN),
                 MathTex('D').next_to(d,DOWN)
                 )